package com.hankol.newretail.adapter.details

import android.os.Bundle
import android.widget.TextView
import com.baselibrary.Constants
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.manager.SensorsDataManager
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.GlideUtils
import com.baselibrary.view.MaskImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.newretail.R
import com.hankol.newretail.bean.goods_details.DaManReviewBean
import com.hankol.newretail.bean.goods_details.GoodsDetails
import java.util.*

/**
 * @author: 关忆北、
 * @date: 2022/7/29
 * @Des：达人评测
 */
class GoodsEvaluatingAdapter : BaseQuickAdapter<DaManReviewBean, BaseViewHolder>(R.layout.item_goods_evaluat_layout) {
    private var mOnItemClickListener: OnItemClickListener? = null
    private var mGoodsDetail: GoodsDetails? = null
    fun setGoodsDetail(mGoodsDetail: GoodsDetails) {
        this.mGoodsDetail = mGoodsDetail
    }
    fun setOnItemClickListener(mOnItemClickListener: OnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener
    }

    override fun convert(helper: BaseViewHolder, item: DaManReviewBean) {
        GlideUtils.loadImg_101(mContext.applicationContext, item.cover, helper.getView(R.id.iv_evaluate_cover))
        val options = MaskImageView.setGaussBlur(mContext)
        Glide.with(mContext).load(item.cover).placeholder(R.drawable.ic_def_hanxiang_228).apply(options).into(helper.getView<MaskImageView>(R.id.iv_evaluate_cover_mask))

        val tvEvaluateName = helper.getView<TextView>(R.id.tv_evaluate_name)
        tvEvaluateName.paint.isFakeBoldText = true
        tvEvaluateName.text = item.name
        helper.setGone(R.id.iv_evaluate_video, item.videoUrl.checkNotNull())



        helper.itemView.setOnClickListener {
            mGoodsDetail?.let {
                SensorsDataManager.instance.pcvideoClick(it.spuId.toString(),if (it.shopInfo == null) "酣客总社" else it.shopInfo.name.checkValue(), it.name.checkValue(), item.id.toString(), item.name.checkValue())
            }

            val bundle = Bundle()
            val imgList: ArrayList<String> = ArrayList<String>()
            data.forEach {
                if (it.videoUrl.checkNotNull()) {
                    imgList.add(it.videoUrl)
                } else {
                    imgList.add(it.cover)
                }
            }
            mOnItemClickListener?.itemClickListener()
            bundle.putStringArrayList(Constants.WIKI_PICTURE_LIST, imgList)
            bundle.putInt(Constants.WIKI_PICTURE_INDEX, helper.adapterPosition)
            ActivityRouter.startActivity(ActivityRouter.ACTIVITY.BROWSE_MEDIA, bundle)
        }
    }

    interface OnItemClickListener {
        fun itemClickListener()
    }

}